#include "MemoryManager.h"
#include <stdio.h>

void print_binary_CHAR(unsigned char value){
	int i;
	for(i = 0; i <= 7; i++){
		if( (value >> (7 - i)) % 2 == 1)
			printf("1");
		else
			printf("0");
		if((i+1)%4 == 0)
			printf(" ");
		if((i+1)%8 == 0)
			printf("  ");
	}
}
void print_binary_SHORT_UINT(short unsigned int value){
	int i;

	for(i = 0; i <= 15; i++){
		if( (value >> (15 - i)) % 2 == 1)
			printf("1");
		else
			printf("0");
		if((i+1)%4 == 0)
			printf(" ");
		if((i+1)%8 == 0)
			printf("  ");
	}
}

void print_pagetable(short unsigned int page){
	short unsigned int index = page;
	int count = 1;
	printf("PAGE TABLE %hu : \n",index);
	printf("\tpage#\tpage addr\n");
	while(index != 0)
	{
		printf("\t%d\t%hu\n",count, index);
		index = get_page_address(&pagetable[index]);
		count++;
	}
	printf("Allocated Pages : %d\n", allocatedPages);
}

void print_all_alloc(){
	int i;
	printf("Printing all allocated pagetable entries\n");
	for(i = 1; i < 16384; i++)
	{
		if(get_page_alloc(&pagetable[i]) == 1)
			printf("%d\t%hu\n",i,get_page_address(&pagetable[i]));
	}
}

int memtest(){
	int pt1, pt2, pt3, i;
	unsigned int bob;
	unsigned char bob2[3];
	init_pagetable();
	
	
	pt1 = alloc_pt(5);
	pt2 = alloc_pt(5);
	
	//printf("%d",get_physical_address(pt2, 20479));	

	bob = 255;
	int_to_chars(bob, bob2);
	printf("%u %u %u \n",bob2[0], bob2[1], bob2[2]);
	print_binary_CHAR(bob2[0]);
	print_binary_CHAR(bob2[1]);
	print_binary_CHAR(bob2[2]);

	//print_binary_CHAR('A');


	/*set_page_valid(&pagetable[0],1);
	set_page_valid(&pagetable[0],0);
	set_page_alloc(&pagetable[0],0);
	set_page_address(&pagetable[0],0);
	print_binary(pagetable[0]);
	printf("\n");
	printf("%hu, %hu, %hu", get_page_valid(&pagetable[0]), get_page_alloc(&pagetable[0]), get_page_address(&pagetable[0]));
	*/
	return 0;

}